package ferp.center.network;

import com.google.gson2.Gson;
import ferp.core.game.Game;
import ferp.core.player.Profile;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * User: igorgok
 * Date: 10/26/12 5:07 PM
 */
public class RequestGameReportSend
{
/*
  public static final class CardViewData
  {
    public String card;
    public boolean visible;
    public boolean enabled;
  }
*/

  // center ID
  public long centerId;
  // profile name
  public String name;
  // reporter email
  public String email;
  // app version
  public String version;
  // description
  public String description;
  // saved game object in JSON format
  public String game;
  // saved Profile.Games object in JSON format (new requests starting from v35)
  public String games;
  // saved game settings in JSON format
  public String settings;
  // total statistics for the current configuration in JSON format
  public String statistics;
  // exception message
  public String exception;
  // memory statistics
  public Game.ServiceData service;
  // player hand information
  //public List<CardViewData> cvs;
  // move candidates
  public String candidates;

  public RequestGameReportSend()
  {
    /* empty constructor */
  }

  public RequestGameReportSend(Profile profile, String version, String email, String description, Exception e, Gson gson)
  {
    this.centerId = profile != null ? profile.centerId : 0;
    this.name = profile != null ? profile.nickname : null;
    this.games = profile != null ? gson.toJson(profile.games()) : null;
    this.settings = profile != null ? gson.toJson(profile.settings) : null;
    this.statistics = profile != null ? gson.toJson(profile.getStatistics()) : null;
    this.email = email;
    this.version = version;
    this.description = description;
    this.service = profile != null ? profile.game().service : null;
    //this.cvs = cvs;
    //this.candidates = candidates;

    if (e != null)
    {
      StringWriter sw = new StringWriter(1024);
      PrintWriter pw = new PrintWriter(sw);

      e.printStackTrace(pw);

      this.exception = sw.toString();
    }
  }
}
